<template>
  <div>
    <h2>登录</h2>
    <input type="text" v-model="user.customerName" placeholder="用户名"><br>
    <input type="password" v-model="user.loginPassword" placeholder="密码"><br>
    <input type="text" v-model="user.code" placeholder="验证码"><br>
    <img :src="captchaImage" @click="generateCaptcha" alt="验证码"><br>
    <button @click="login">登录</button>
  </div>
</template>

<script>


import {uuid} from "@/utils";

export default {
  data() {
    return {
      user:{},
      captchaImage: ''
    };
  },
  methods: {
    generateCaptcha() {
      this.axios.get('/customer/CustomerGenerator',{params:{uid:uuid()}})
          .then(response => {
            this.captchaImage = response.data.data;
          })
          .catch(error => {
            console.error(error);
          });
    },
    login() {
      this.axios.post('/customer/login', this.user)
          .then(response => {
            console.log(response.data);
            alert(response.data.msg)
            // 处理登录成功的逻辑
            this.$router.push("customer")
          })
          .catch(error => {
            console.error(error.response.data);
          });
    }
  },created() {
    this.generateCaptcha();
  }
};
</script>

<style scoped>

</style>